package com.ruoyi.teaching.service.impl;

import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.teaching.vo.MyStageTaskVO;
import com.ruoyi.teaching.vo.StageTaskSubmitVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.teaching.mapper.YaStageTaskMapper;
import com.ruoyi.teaching.domain.YaStageTask;
import com.ruoyi.teaching.service.IYaStageTaskService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 阶段任务Service业务层处理
 *
 * @author ruoyi
 * @date 2025-03-12
 */
@Service
public class YaStageTaskServiceImpl implements IYaStageTaskService
{
    @Autowired
    private YaStageTaskMapper yaStageTaskMapper;

    /**
     * 查询阶段任务
     *
     * @param taskId 阶段任务主键
     * @return 阶段任务
     */
    @Override
    public YaStageTask selectYaStageTaskByTaskId(Long taskId)
    {
        return yaStageTaskMapper.selectYaStageTaskByTaskId(taskId);
    }

    /**
     * 查询阶段任务列表
     *
     * @param yaStageTask 阶段任务
     * @return 阶段任务
     */
    @Override
    public List<YaStageTask> selectYaStageTaskList(YaStageTask yaStageTask)
    {
        return yaStageTaskMapper.selectYaStageTaskList(yaStageTask);
    }

    /**
     * 新增阶段任务
     *
     * @param yaStageTask 阶段任务
     * @return 结果
     */
    @Override
    public int insertYaStageTask(YaStageTask yaStageTask)
    {
        yaStageTask.setCreateTime(DateUtils.getNowDate());
        return yaStageTaskMapper.insertYaStageTask(yaStageTask);
    }

    /**
     * 修改阶段任务
     *
     * @param yaStageTask 阶段任务
     * @return 结果
     */
    @Override
    public int updateYaStageTask(YaStageTask yaStageTask)
    {
        yaStageTask.setUpdateTime(DateUtils.getNowDate());
        return yaStageTaskMapper.updateYaStageTask(yaStageTask);
    }

    /**
     * 批量删除阶段任务
     *
     * @param taskIds 需要删除的阶段任务主键
     * @return 结果
     */
    @Override
    public int deleteYaStageTaskByTaskIds(Long[] taskIds)
    {
        return yaStageTaskMapper.deleteYaStageTaskByTaskIds(taskIds);
    }

    /**
     * 删除阶段任务信息
     *
     * @param taskId 阶段任务主键
     * @return 结果
     */
    @Override
    public int deleteYaStageTaskByTaskId(Long taskId)
    {
        return yaStageTaskMapper.deleteYaStageTaskByTaskId(taskId);
    }

    @Override
    @Transactional(readOnly = true)
    public List<MyStageTaskVO> selectMyStageTaskList(YaStageTask yaStageTask) {
        //获取当前用户
        Long studentId = SecurityUtils.getUserId();
        return yaStageTaskMapper.selectMyStageTaskList(studentId);
    }

    @Override
    @Transactional(readOnly = true)
    public List<StageTaskSubmitVO> selectSubmitList(Long taskId, Long classesId) {
        return yaStageTaskMapper.selectSubmitList(taskId, classesId);
    }
}
